1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module sourceview.SnippetManager;
26 
27 private import gio.ListModelIF;
28 private import glib.Str;
29 private import glib.c.functions;
30 private import gobject.ObjectG;
31 private import sourceview.Snippet;
32 private import sourceview.c.functions;
33 public  import sourceview.c.types;
34 
35 
36 /**
37  * Provides access to [class@Snippet].
38  * 
39  * `GtkSourceSnippetManager` is an object which processes snippet description
40  * files and creates [class@Snippet] objects.
41  * 
42  * Use [func@SnippetManager.get_default] to retrieve the default
43  * instance of `GtkSourceSnippetManager`.
44  * 
45  * Use [method@SnippetManager.get_snippet] to retrieve snippets for
46  * a given snippets.
47  */
48 public class SnippetManager : ObjectG
49 {
50 	/** the main Gtk struct */
51 	protected GtkSourceSnippetManager* gtkSourceSnippetManager;
52 
53 	/** Get the main Gtk struct */
54 	public GtkSourceSnippetManager* getSnippetManagerStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return gtkSourceSnippetManager;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected override void* getStruct()
63 	{
64 		return cast(void*)gtkSourceSnippetManager;
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (GtkSourceSnippetManager* gtkSourceSnippetManager, bool ownedRef = false)
71 	{
72 		this.gtkSourceSnippetManager = gtkSourceSnippetManager;
73 		super(cast(GObject*)gtkSourceSnippetManager, ownedRef);
74 	}
75 
76 
77 	/** */
78 	public static GType getType()
79 	{
80 		return gtk_source_snippet_manager_get_type();
81 	}
82 
83 	/**
84 	 * Returns the default #GtkSourceSnippetManager instance.
85 	 *
86 	 * Returns: a #GtkSourceSnippetManager which
87 	 *     is owned by GtkSourceView library and must not be unref'd.
88 	 */
89 	public static SnippetManager getDefault()
90 	{
91 		auto __p = gtk_source_snippet_manager_get_default();
92 
93 		if(__p is null)
94 		{
95 			return null;
96 		}
97 
98 		return ObjectG.getDObject!(SnippetManager)(cast(GtkSourceSnippetManager*) __p);
99 	}
100 
101 	/**
102 	 * Gets the list directories where @self looks for snippet files.
103 	 *
104 	 * Returns: %NULL-terminated array
105 	 *     containing a list of snippet files directories.
106 	 *     The array is owned by @lm and must not be modified.
107 	 */
108 	public string[] getSearchPath()
109 	{
110 		return Str.toStringArray(gtk_source_snippet_manager_get_search_path(gtkSourceSnippetManager));
111 	}
112 
113 	/**
114 	 * Queries the known snippets for the first matching @group, @language_id,
115 	 * and/or @trigger.
116 	 *
117 	 * If @group or @language_id are %NULL, they will be ignored.
118 	 *
119 	 * Params:
120 	 *     group = a group name or %NULL
121 	 *     languageId = a #GtkSourceLanguage:id or %NULL
122 	 *     trigger = the trigger for the snippet
123 	 *
124 	 * Returns: a #GtkSourceSnippet or %NULL if no
125 	 *     matching snippet was found.
126 	 */
127 	public Snippet getSnippet(string group, string languageId, string trigger)
128 	{
129 		auto __p = gtk_source_snippet_manager_get_snippet(gtkSourceSnippetManager, Str.toStringz(group), Str.toStringz(languageId), Str.toStringz(trigger));
130 
131 		if(__p is null)
132 		{
133 			return null;
134 		}
135 
136 		return ObjectG.getDObject!(Snippet)(cast(GtkSourceSnippet*) __p, true);
137 	}
138 
139 	/**
140 	 * List all the known groups within the snippet manager.
141 	 *
142 	 * The result should be freed with g_free(), and the individual strings are
143 	 * owned by @self and should never be freed by the caller.
144 	 *
145 	 * Returns: An array of strings which should be freed with g_free().
146 	 */
147 	public string[] listGroups()
148 	{
149 		auto retStr = gtk_source_snippet_manager_list_groups(gtkSourceSnippetManager);
150 
151 		scope(exit) g_free(retStr);
152 		return Str.toStringArray(retStr);
153 	}
154 
155 	/**
156 	 * Queries the known snippets for those matching @group, @language_id, and/or
157 	 * @trigger_prefix.
158 	 *
159 	 * If any of these are %NULL, they will be ignored when filtering the available snippets.
160 	 *
161 	 * The [iface@Gio.ListModel] only contains information about the available snippets until
162 	 * [method@Gio.ListModel.get_item] is called for a specific snippet. This helps reduce
163 	 * the number of [class@GObject.Object]'s that are created at runtime to those needed by
164 	 * the calling application.
165 	 *
166 	 * Params:
167 	 *     group = a group name or %NULL
168 	 *     languageId = a #GtkSourceLanguage:id or %NULL
169 	 *     triggerPrefix = a prefix for a trigger to activate
170 	 *
171 	 * Returns: a #GListModel of #GtkSourceSnippet.
172 	 */
173 	public ListModelIF listMatching(string group, string languageId, string triggerPrefix)
174 	{
175 		auto __p = gtk_source_snippet_manager_list_matching(gtkSourceSnippetManager, Str.toStringz(group), Str.toStringz(languageId), Str.toStringz(triggerPrefix));
176 
177 		if(__p is null)
178 		{
179 			return null;
180 		}
181 
182 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p, true);
183 	}
184 
185 	/**
186 	 * Sets the list of directories in which the `GtkSourceSnippetManager` looks for
187 	 * snippet files.
188 	 *
189 	 * If @dirs is %NULL, the search path is reset to default.
190 	 *
191 	 * At the moment this function can be called only before the
192 	 * snippet files are loaded for the first time. In practice
193 	 * to set a custom search path for a `GtkSourceSnippetManager`,
194 	 * you have to call this function right after creating it.
195 	 *
196 	 * Params:
197 	 *     dirs = a %NULL-terminated array of
198 	 *         strings or %NULL.
199 	 */
200 	public void setSearchPath(string[] dirs)
201 	{
202 		gtk_source_snippet_manager_set_search_path(gtkSourceSnippetManager, Str.toStringzArray(dirs));
203 	}
204 }